var map,mposctl,vectors, geojson,markers,selectControl;
var selectedFeature;
//Init
map = new OpenLayers.Map('floor5');
layer = new OpenLayers.Layer.Image(
    "floor5",
    "floor5.jpg",
    new OpenLayers.Bounds(-1091,-282,1091,282),
    new OpenLayers.Size(2182,564)
);
map.addLayer(layer);
map.zoomToMaxExtent();
var featurecollection = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_92",
            "properties": {
                "name": "Biomedical Engineering Lab",
                "description": "Lab room for BME Students"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -1082,
                            262
                        ],
                        [
                            -799,
                            259
                        ],
                        [
                            -800,
                            48
                        ],
                        [
                            -1081,
                            47
                        ],
                        [
                            -1082,
                            262
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_114",
            "properties": {
                "name": "Biotechnology office",
                "description": "the working office of BT school"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -1081,
                            41
                        ],
                        [
                            -801,
                            40
                        ],
                        [
                            -802,
                            -173
                        ],
                        [
                            -1082,
                            -174
                        ],
                        [
                            -1081,
                            41
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_136",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -684,
                            261
                        ],
                        [
                            -564,
                            259
                        ],
                        [
                            -564,
                            73
                        ],
                        [
                            -684,
                            72
                        ],
                        [
                            -684,
                            261
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_158",
            "properties": {
                "name": "Elevator_5",
                "description": "Elevator of Floor 5"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -687,
                            -51
                        ],
                        [
                            -546,
                            -54
                        ],
                        [
                            -545,
                            -168
                        ],
                        [
                            -688,
                            -168
                        ],
                        [
                            -687,
                            -51
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_182",
            "properties": {
                "name": "Stair_5",
                "description": "Stair of Floor 5"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -754,
                            -176
                        ],
                        [
                            -693,
                            -178
                        ],
                        [
                            -693,
                            -249
                        ],
                        [
                            -754,
                            -251
                        ],
                        [
                            -754,
                            -176
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_204",
            "properties": {
                "name": "Department of Industrial System Engineering/ Department of Physics",
                "description": "the working office of ISE and Physics School"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -540,
                            -52
                        ],
                        [
                            -335,
                            -53
                        ],
                        [
                            -336,
                            -168
                        ],
                        [
                            -542,
                            -169
                        ],
                        [
                            -540,
                            -52
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_228",
            "properties": {
                "name": "A.503",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -560,
                            260
                        ],
                        [
                            -378,
                            260
                        ],
                        [
                            -377,
                            74
                        ],
                        [
                            -559,
                            74
                        ],
                        [
                            -560,
                            260
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_250",
            "properties": {
                "name": "A.504",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -375,
                            261
                        ],
                        [
                            -197,
                            260
                        ],
                        [
                            -195,
                            74
                        ],
                        [
                            -375,
                            74
                        ],
                        [
                            -375,
                            261
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_274",
            "properties": {
                "name": "A.505",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -192,
                            260
                        ],
                        [
                            -1,
                            260
                        ],
                        [
                            0,
                            72
                        ],
                        [
                            -191,
                            73
                        ],
                        [
                            -192,
                            260
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_296",
            "properties": {
                "name": "A.506",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            4,
                            259
                        ],
                        [
                            181,
                            259
                        ],
                        [
                            181,
                            73
                        ],
                        [
                            4,
                            73
                        ],
                        [
                            4,
                            259
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_318",
            "properties": {
                "name": "Professors' office",
                "description": "the working office of all professors"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -331,
                            -52
                        ],
                        [
                            -122,
                            -54
                        ],
                        [
                            -121,
                            -167
                        ],
                        [
                            -332,
                            -167
                        ],
                        [
                            -331,
                            -52
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_340",
            "properties": {
                "name": "Department of Mathematics",
                "description": "the working office of Mathematics school"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -116,
                            -52
                        ],
                        [
                            104,
                            -52
                        ],
                        [
                            105,
                            -167
                        ],
                        [
                            -117,
                            -167
                        ],
                        [
                            -116,
                            -52
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_364",
            "properties": {
                "name": "A.507",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            186,
                            263
                        ],
                        [
                            380,
                            262
                        ],
                        [
                            379,
                            74
                        ],
                        [
                            188,
                            74
                        ],
                        [
                            186,
                            263
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_386",
            "properties": {
                "name": "Cleaning Services",
                "description": "supplying the cleaning services for the university"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            108,
                            -52
                        ],
                        [
                            335,
                            -53
                        ],
                        [
                            335,
                            -167
                        ],
                        [
                            110,
                            -168
                        ],
                        [
                            108,
                            -52
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_410",
            "properties": {
                "name": "A.508",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            383,
                            260
                        ],
                        [
                            569,
                            260
                        ],
                        [
                            570,
                            73
                        ],
                        [
                            385,
                            74
                        ],
                        [
                            383,
                            260
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_432",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            338,
                            -54
                        ],
                        [
                            521,
                            -54
                        ],
                        [
                            520,
                            -170
                        ],
                        [
                            342,
                            -172
                        ],
                        [
                            338,
                            -54
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_454",
            "properties": {
                "name": "Elevator_5",
                "description": "Elevator of Floor 5"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            527,
                            -52
                        ],
                        [
                            673,
                            -54
                        ],
                        [
                            673,
                            -168
                        ],
                        [
                            526,
                            -169
                        ],
                        [
                            527,
                            -52
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_493",
            "properties": {
                "name": "Language Lab",
                "description": "for students praticing speaking and listening for English Department"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            818,
                            261
                        ],
                        [
                            1087,
                            261
                        ],
                        [
                            1086,
                            41
                        ],
                        [
                            822,
                            42
                        ],
                        [
                            818,
                            261
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_517",
            "properties": {
                "name": "Department of English/ Writing Center",
                "description": "the working office of English Department"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            821,
                            34
                        ],
                        [
                            1084,
                            36
                        ],
                        [
                            1086,
                            -169
                        ],
                        [
                            821,
                            -169
                        ],
                        [
                            821,
                            34
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_539",
            "properties": {
                "name": "Stair_5",
                "description": "Stair of Floor 5"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            675,
                            -174
                        ],
                        [
                            753,
                            -174
                        ],
                        [
                            753,
                            -252
                        ],
                        [
                            674,
                            -250
                        ],
                        [
                            675,
                            -174
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_563",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            573,
                            260
                        ],
                        [
                            671,
                            260
                        ],
                        [
                            673,
                            74
                        ],
                        [
                            575,
                            74
                        ],
                        [
                            573,
                            260
                        ]
                    ]
                ]
            }
        }
    ]
}
geojson = new OpenLayers.Format.GeoJSON();
vectors = new OpenLayers.Layer.Vector();
selectControl= new OpenLayers.Control.SelectFeature(vectors,
    {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
map.addLayer(vectors);
vectors.addFeatures(geojson.read(featurecollection));
map.addControl(selectControl);
selectControl.activate();
function onPopupClose(){selectControl.unselect(selectedFeature);};
function onFeatureSelect(feature){
    selectedFeature = feature;
    popup = new OpenLayers.Popup.FramedCloud(feature.id + "pop", feature.geometry.getBounds().getCenterLonLat(),null,"<div style='font-size:.8em'>Room: " + feature.attributes.name + "<br />Description: " + feature.attributes.description + "</div>",null, true, onPopupClose);
    feature.popup = popup;
    map.addPopup(popup);
}
function onFeatureUnselect(feature){
    map.removePopup(feature.popup);
    feature.popup.destroy();
    feature.popup = null;
}
